home *** CD-ROM | disk | FTP | other *** search
/ Mac Mania 5 / MacMania 5.toast / / Internet software / NewsWatcher / NW Source / Source / olddrag.c < prev    next >
Text File  |  1997-01-09  |  8KB  |  287 lines

  1. /*----------------------------------------------------------------------------
  2.  
  3.     olddrag.c
  4.  
  5.     This module handles drag and drop when the Drag Manager is not
  6.     available.
  7.     
  8.     Copyright © 1994-1997, Northwestern University.
  9.  
  10. ----------------------------------------------------------------------------*/
  11.  
  12. #include <stdio.h>
  13.  
  14. #include "glob.h"
  15. #include "olddrag.h"
  16. #include "subscribe.h"
  17. #include "windutil.h"
  18. #include "biglist.h"
  19. #include "wind.h"
  20.  
  21.  
  22.  
  23. static BigListRef gTargetList;    /* list ref for current target list
  24.                                    containing item dividing line, or
  25.                                    nil if none. */
  26. static long gTargetItem;        /* item number of item following current
  27.                                    item dividing line, or -1 if none */
  28.  
  29.  
  30.  
  31. /*----------------------------------------------------------------------------
  32.     OldWaitMouseMoved
  33.     
  34.     A version of the Drag Manager function "WaitMouseMoved" for when
  35.     we do not have the Drag Manager.
  36.     
  37.     Entry:    where = mouse location in global coordinates.
  38.             
  39.     Exit:    function result = true if mouse moved.
  40. ----------------------------------------------------------------------------*/
  41.  
  42. static Boolean OldWaitMouseMoved (Point where)
  43. {
  44.     Rect r;
  45.  
  46.     SetRect(&r, where.h-3, where.v-3, where.h+3, where.v+3);
  47.     while (StillDown()) {
  48.         GetMouse(&where);
  49.         LocalToGlobal(&where);
  50.         if (!PtInRect(where, &r)) return true;
  51.     }
  52.     return false;
  53. }
  54.  
  55.  
  56.  
  57. /*----------------------------------------------------------------------------
  58.     HilightTarget
  59.     
  60.     Hilight a drag target list when we do not have the Drag Manager.
  61.     
  62.     Entry:    groupDrag = true if we're dragging groups, false if we're
  63.                 dragging subject in the extract binaries manually dialog.
  64.             srcList = list ref for the list where the drag was started.
  65.             where = current mouse location in global coordinates.
  66.             fullPort = pointer to grafport for drawing drag region.
  67.             dragRgn = handle to drag region.
  68. ----------------------------------------------------------------------------*/
  69.  
  70. static void HilightTarget (Boolean groupDrag, BigListRef srcList, Point where,
  71.     GrafPtr fullPort, RgnHandle dragRgn)
  72. {
  73.     WindowPtr srcWind, destWind;
  74.     TWindow **srcInfo, **destInfo;
  75.     BigListRef targetList;
  76.     long targetItem;
  77.     GrafPtr port;
  78.     Rect rView, contentRect;
  79.     long scrollDelta, visTop, visBottom, numItems;
  80.     
  81.     GetPort(&port);
  82.     targetList = nil;
  83.     targetItem = -1;
  84.     srcWind = BigLGetWindow(srcList);
  85.     FindWindow(where, &destWind);
  86.     if (destWind != nil) {
  87.         if (groupDrag) {
  88.             srcInfo = (TWindow**)GetWRefCon(srcWind);
  89.             if (GetMyWindowKind(destWind) == kGroup) {
  90.                 destInfo = (TWindow**)GetWRefCon(destWind);
  91.                 if ((**srcInfo).groupKind == kUserGroup) {
  92.                     if (destWind == srcWind) {
  93.                         targetList = srcList;
  94.                     }
  95.                 } else {
  96.                     if ((**destInfo).groupKind == kUserGroup) {
  97.                         targetList = (**destInfo).groupList;
  98.                     }
  99.                 }
  100.             }
  101.         } else {
  102.             if (destWind == srcWind) {
  103.                 targetList = srcList;
  104.             }
  105.         }
  106.         if (targetList != nil) {
  107.             BigLGetViewRect(targetList, &rView);
  108.             SetRect(&contentRect, rView.left, 0, rView.right-15, rView.bottom+15);
  109.             SetPort(destWind);
  110.             GlobalToLocal(&where);
  111.             if (PtInRect(where, &contentRect)) {
  112.                 scrollDelta = 0;
  113.                 BigLGetVisibleItems(targetList, &visTop, &visBottom);
  114.                 numItems = BigLGetNumItems(targetList);
  115.                 if (where.v < rView.top && visTop > 0) {
  116.                     scrollDelta = -1;
  117.                 } else if (where.v >= rView.bottom && visBottom < numItems-1) {
  118.                     scrollDelta = +1;
  119.                 }
  120.                 if (scrollDelta != 0) {
  121.                     if (gTargetList != nil && gTargetItem != -1) {
  122.                         BigLDrawItemDividingLine(gTargetList, gTargetItem);
  123.                         gTargetList = nil;
  124.                         gTargetItem = -1;
  125.                     }
  126.                     SetPort(fullPort);
  127.                     FrameRgn(dragRgn);
  128.                     BigLScroll(targetList, scrollDelta);
  129.                     FrameRgn(dragRgn);
  130.                     SetPort(destWind);
  131.                 }
  132.                 targetItem = BigLGetDividingLineGivenPoint(targetList, where);
  133.             }
  134.         }
  135.     }
  136.     if (targetList != gTargetList || targetItem != gTargetItem) {
  137.         if (gTargetList != nil && gTargetItem != -1) {
  138.             BigLDrawItemDividingLine(gTargetList, gTargetItem);
  139.         }
  140.         if (targetList != nil && targetItem != -1) {
  141.             BigLDrawItemDividingLine(targetList, targetItem);
  142.         }
  143.         gTargetList = targetList;
  144.         gTargetItem = targetItem;
  145.     }
  146.     SetPort(port);
  147. }
  148.  
  149.  
  150.  
  151. /*----------------------------------------------------------------------------
  152.     OldTrackDrag
  153.     
  154.     Track a drag when we do not have the Drag Manager.
  155.     
  156.     Entry:    groupDrag = true if we're dragging groups, false if we're
  157.                 dragging subject in the extract binaries manually dialog.
  158.             theList = list ref.
  159. ----------------------------------------------------------------------------*/
  160.  
  161. static void OldTrackDrag (Boolean groupDrag, BigListRef theList)
  162. {
  163.     RgnHandle dragRgn = nil;
  164.     Point prevPt, curPt;
  165.     GrafPtr port;
  166.     GrafPort fullPort;
  167.     
  168.     GetPort(&port);
  169.     BigLBuildSelectedItemsDragRegion(theList, &dragRgn);
  170.     GetMouse(&curPt);
  171.     LocalToGlobal(&curPt);
  172.     OpenPort(&fullPort);
  173.     CopyRgn(GetGrayRgn(), fullPort.visRgn);
  174.     fullPort.portRect = (**GetGrayRgn()).rgnBBox;
  175.     PenPat(&qd.gray);
  176.     PenMode(patXor);
  177.     FrameRgn(dragRgn);
  178.     prevPt = curPt;
  179.     gTargetList = nil;
  180.     gTargetItem = -1;
  181.     while (StillDown()) {
  182.         GetMouse(&curPt);
  183.         LocalToGlobal(&curPt);
  184.         if (!EqualPt(curPt, prevPt)) {
  185.             FrameRgn(dragRgn);
  186.             OffsetRgn(dragRgn, curPt.h - prevPt.h, curPt.v - prevPt.v);
  187.             FrameRgn(dragRgn);
  188.             prevPt = curPt;
  189.         }
  190.         HilightTarget(groupDrag, theList, curPt, &fullPort, dragRgn);
  191.     }
  192.     if (gTargetList != nil && gTargetItem != -1) {
  193.         BigLDrawItemDividingLine(gTargetList, gTargetItem);
  194.     }
  195.     FrameRgn(dragRgn);
  196.     DisposeRgn(dragRgn);
  197.     ClosePort(&fullPort);
  198.     SetPort(port);
  199. }
  200.  
  201.  
  202.  
  203. /*----------------------------------------------------------------------------
  204.     OldGroupListClickLoop
  205.     
  206.     The click loop function for group lists when we do not have the
  207.     Drag Manager. It initiates group drags.
  208.     
  209.     Entry:    theList = list ref.
  210.             where = mouse location, in local coords.
  211.             modifiers = modifiers field from event record.
  212.             helperItem = 
  213.                 for shift-click, the item number of the item at the
  214.                     other end of the selection range from the initially 
  215.                     clicked item (the "anchor" item for a shift-drag).
  216.                 otherwise, the item number of the initially clicked item.
  217.             
  218.     Exit:    function result = error code.
  219. ----------------------------------------------------------------------------*/
  220.  
  221. OSErr OldGroupListClickLoop (BigListRef theList, Point where,
  222.     short modifiers, long helperItem)
  223. {
  224.     WindowPtr srcWind;
  225.     TWindow **srcInfo;
  226.  
  227.     if ((modifiers & shiftKey) != 0 || (modifiers & cmdKey) != 0) {
  228.         return BigLDefaultClickLoop(theList, where, modifiers, helperItem);
  229.     }
  230.     
  231.     LocalToGlobal(&where);
  232.     if (OldWaitMouseMoved(where)) {
  233.         OldTrackDrag(true, theList);
  234.         if (gTargetItem >= 0) {
  235.             srcWind = BigLGetWindow(theList);
  236.             srcInfo = (TWindow**)GetWRefCon(srcWind);
  237.             if ((**srcInfo).groupKind == kUserGroup) {
  238.                 BigLMoveSelectedItems(theList, theList, gTargetItem, nil);
  239.             } else {
  240.                 CopyOrMoveSelectedGroups(srcWind, 
  241.                     BigLGetWindow(gTargetList),
  242.                     gTargetItem,
  243.                     true);
  244.             }
  245.         }
  246.     }
  247.     
  248.     return noErr;
  249. }
  250.  
  251.  
  252.  
  253. /*----------------------------------------------------------------------------
  254.     OldExtractBinariesManuallyClickLoop
  255.     
  256.     The click loop function for the list in the extract binaries manually
  257.     dialog when we do not have the Drag Manager. It initiates item drags.
  258.     
  259.     Entry:    theList = list ref.
  260.             where = mouse location, in local coords.
  261.             modifiers = modifiers field from event record.
  262.             helperItem = 
  263.                 for shift-click, the item number of the item at the
  264.                     other end of the selection range from the initially 
  265.                     clicked item (the "anchor" item for a shift-drag).
  266.                 otherwise, the item number of the initially clicked item.
  267.             
  268.     Exit:    function result = error code.
  269. ----------------------------------------------------------------------------*/
  270.  
  271. OSErr OldExtractBinariesManuallyClickLoop (BigListRef theList, Point where,
  272.     short modifiers, long helperItem)
  273. {
  274.     if ((modifiers & shiftKey) != 0 || (modifiers & cmdKey) != 0) {
  275.         return BigLDefaultClickLoop(theList, where, modifiers, helperItem);
  276.     }
  277.     
  278.     LocalToGlobal(&where);
  279.     if (OldWaitMouseMoved(where)) {
  280.         OldTrackDrag(false, theList);
  281.         if (gTargetItem >= 0) {
  282.             BigLMoveSelectedItems(theList, theList, gTargetItem, nil);
  283.         }
  284.     }
  285.     
  286.     return noErr;
  287. }